package com.xxxx.blog.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.blog.entity.ArticleTag;
import com.xxxx.blog.mapper.ArticleTagMapper;
import com.xxxx.blog.service.ArticleTagService;
import com.xxxx.blog.utils.Maps;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@AllArgsConstructor
@Service
public class ArticleTagServiceImpl extends ServiceImpl<ArticleTagMapper,ArticleTag> implements ArticleTagService {

    private final ArticleTagMapper articleTagMapper;

    public int create(ArticleTag tag){
        return articleTagMapper.create(tag);
    }

    public int delete(Integer id){
        return articleTagMapper.delete(Maps.build(id).getMap());
    }

    public int update(ArticleTag tag){
        return articleTagMapper.update(Maps.build(tag.getId()).beanToMapForUpdate(tag));
    }

    public PageInfo<ArticleTag> query(ArticleTag tag){
        if(tag != null && tag.getPage() != null){
            PageHelper.startPage(tag.getPage(),tag.getLimit());
        }
        List<ArticleTag> list = articleTagMapper.query(Maps.build().beanToMap(tag));
        return new PageInfo<ArticleTag>(list);
    }

    public ArticleTag detail(Integer id){
        return articleTagMapper.detail(Maps.build(id).getMap());
    }

    public int count(ArticleTag tag){
        return articleTagMapper.count(Maps.build().beanToMap(tag));
    }




}
